package com.jh.concurrent.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title ThreadPoolDemo.java
 * @package com.jh.concurrent.threadpool
 * @description 线程池demo
 * @date 2019-05-27 09:57
 */
public class ThreadPoolDemo implements Runnable{

    @Override
    public void run() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName());
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new ThreadPoolDemo());
        }

        executorService.shutdown();
    }
}
